home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: New Zealand Amiga Users Group / New Zealand Amiga Users Group Newsdisk v07 (1987-08)(NZAmigaUG).zip / New Zealand Amiga Users Group Newsdisk v07 (1987-08)(NZAmigaUG).adf / ANSI Fix.BAS < prev    next >
BASIC Source File  |  1993-12-02  |  2KB  |  60 lines

  1. REM Program to fix 'printer ready' files containing ANSI attribute sequences
  2. REM so that the CONSOLE device driver handles them properly.
  3. REM The problem is that the CONSOLE device driver doesn't recognise the
  4. REM underline, bold, and italic OFF sequences.  So I substitute the Plain
  5. REM text attribute. This simple approach works except when you turn on
  6. REM more than one attribute, then turn off only one. eg a paragraph
  7. REM displayed in italics with an underlined bit in the middle results in
  8. REM the the italics being turned off at the end of the underlined bit.
  9. REM To do a proper job you need to design a complete state machine to keep
  10. REM track the attributes - then again you might as well write a new CONSOLE
  11. REM device handler.
  12.  
  13. LINE INPUT "Filename : ";fil$
  14. PRINT "Output file will be called ";fil$+".fixed"
  15. OPEN fil$ FOR INPUT AS #1
  16. OPEN fil$+".fixed" FOR OUTPUT AS #2
  17. WHILE NOT EOF(1)
  18.   b$=""
  19.   l=0
  20.   LINE INPUT # 1,l$
  21.   FOR i=1 TO LEN(l$)
  22.     a$=MID$(l$,i,1)
  23.     IF a$ = CHR$(27) THEN
  24.       l=1
  25.       PRINT #2,a$;
  26.     ELSE
  27.       IF l=1 AND a$="[" THEN
  28.         l=2
  29.         PRINT #2,a$;
  30.       ELSE
  31.         IF (l=2 OR l=3) THEN
  32.           IF a$>="0" AND a$<="9" THEN
  33.             b$=b$+a$
  34.             l=l+1
  35.           ELSE
  36.             PRINT #2,b$;a$;
  37.             b$=""
  38.             l=0
  39.           END IF
  40.         ELSE 
  41.           IF l=4 THEN
  42.             IF a$="m" AND (b$="22" OR b$="23" OR b$="24") THEN b$="0"
  43.             b$=b$+a$
  44.             PRINT #2,b$;
  45.             b$=""
  46.             l=0
  47.           ELSE
  48.             PRINT #2,a$;
  49.           END IF
  50.         END IF
  51.       END IF
  52.     END IF
  53.   NEXT i
  54.   PRINT #2,CHR$(10);
  55. WEND
  56. CLOSE
  57. PRINT "All fixed"
  58. END  
  59.   
  60.